import React, { useMemo } from 'react';
import { moneyFormat } from '@library/components/table/util';
import PrintItem from './../PrintItem';

const App = (props,) => {
  const { formItemProps, initialValue, inputProps } = props;

  const v = useMemo(() => {
    if (!initialValue) return inputProps?.formatterMoney ? '0.00' : '0';
    if (inputProps?.formatterMoney) {
      return moneyFormat(initialValue);
    } else if (inputProps?.precision) {
      return Number(initialValue).toFixed(inputProps.precision);
    }
    return initialValue;
  }, [inputProps, initialValue]);

  return (
    <PrintItem
      style={formItemProps?.style || {}}
      label={localStorage.i18nextLng === 'en' ? formItemProps?.labelEn : formItemProps?.label}>
      {v}
    </PrintItem>
  );
};

export default App;